package com.ytzl.itrip.service;

import com.ytzl.itrip.exception.TokenValidationFailedException;
import com.ytzl.itrip.pojo.ItripUser;

/**
 * Created by sam on 2018/2/8.
 */
public interface TokenService {

    //会话失效时间
    public static final int SESSION_TIMEOUT = 60 * 60 * 2;
    //Token置换保护期
    public static final int REPLACETOKEN__PROTECTION_TIMEOUT = 60 * 60;
    //Token死亡时间
    public static final int REPLACETOKEN__DIE = 2 * 60;

    /**
     * 构建token
     *
     * @param header
     * @param itripUser
     * @return
     */
    String generateToken(String header, ItripUser itripUser);

    /**
     * 保存token
     *
     * @param token
     * @param itripUser
     */
    void save(String token, ItripUser itripUser);

    /**
     * 认证Token是否有效
     *
     * @param header
     * @param token
     * @return
     */
    boolean validate(String header, String token);

    /**
     * 删除Token
     *
     * @param token
     */
    void remove(String token);

    /**
     * 置换Token
     *
     * @param userAgent
     * @param token
     * @return
     */
    String replaceToken(String userAgent, String token) throws TokenValidationFailedException;
}
